const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    usersshow: true,
    userinfo: {
      login_inf: {
        avatarUrl: 'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=257873596,2924686194&fm=26&gp=0.jpg',
        gender: 1,
        nickName: '请先获取取件码'
      }
    }
  },
  //获取用户数据
  getUserProfile(e) {
    let userinfo_inf = wx.getStorageSync('userinfo_inf');
    this.setData({
      userinfo: userinfo_inf,
      usersshow: false
    })
    // wx.getUserProfile({
    //   lang: 'zh_CN',
    //   desc: '用于完善个人资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
    //   success: (res) => {
    //     wx.setStorageSync('userinfo', res.userInfo);
    //     this.setData({
    //       userinfo: res.userInfo,
    //       usersshow: false
    //     })
    //   }
    // })
  },
  //初始化用户数据
  getuserdata() {
    let data = wx.getStorageSync('userinfo_inf')
    if (data != '') {
      this.setData({
        userinfo: data,
        usersshow: false
      })
    }
  },
  //退出登录
  closeSign() {
    wx.setStorageSync('userinfo_inf', '');
    this.setData({
      usersshow: true,
      userinfo: {
        avatarUrl: 'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=257873596,2924686194&fm=26&gp=0.jpg',
        gender: 1,
        nickName: '请点击登录'
      }
    })
  },
  //查看头像
  Lookuesrimage() {
    if (this.data.userinfo.login_inf.nickName == '请先获取取件码') {
      wx.showModal({
        title: '提示', showCancel: false, content: '请先领取收货码',
        success(res) {
          if (res.confirm) { wx.navigateTo({ url: '/packageB/pages/Receipt_code/Receipt_code', }) }
        }
      });
    } else {
      let url = this.data.userinfo.login_inf.avatarUrl
      wx.previewImage({
        current: url, // 当前显示图片的http链接
        urls: [url] // 需要预览的图片http链接列表
      })
    }
  },
  Lookuserinf() {
    let userinfo_inf = wx.getStorageSync('userinfo_inf');
    if (userinfo_inf == '') {
      wx.showModal({
        title: '提示', showCancel: false, content: '请先领取收货码',
        success(res) {
          if (res.confirm) { wx.navigateTo({ url: '/packageB/pages/Receipt_code/Receipt_code', }) }
        }
      });
    } else if (userinfo_inf.login_sincerity < 20) {
      wx.showModal({ title: '严重提示', showCancel: false, content: '你的信誉低，请联系客服增加信誉。', });
    } else {
      wx.navigateTo({
        url: '/packageC/pages/wait_right/wait_right',
      })
    }
  },
  express() {
    let userinfo_inf = wx.getStorageSync('userinfo_inf');
    if (userinfo_inf == '') {
      wx.showModal({
        title: '提示', showCancel: false, content: '请先领取收货码',
        success(res) {
          if (res.confirm) { wx.navigateTo({ url: '/packageB/pages/Receipt_code/Receipt_code', }) }
        }
      });
    } else if (userinfo_inf.login_sincerity < 20) {
      wx.showModal({ title: '严重提示', showCancel: false, content: '你的信誉低，请联系客服增加信誉。', });
    } else {
      wx.navigateTo({
        url: '/packageA/pages/orderinf/orderinf',
      })
    }

  },

  riderLive() {
    let datas = wx.getStorageSync('rider_inf_data');
    if (datas == '') {
      wx.navigateTo({
        url: '/pages/rider_hall/rider_hall',
      })
    } else {
      app.globalData['rider_inf'] = datas;
      wx.navigateTo({
        url: '/packageA/pages/rider_hall/rider_hall',
      })
    }

  },
  address() {
    wx.chooseAddress();
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getuserdata();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.tabBar();
    this.getuserdata();
  },
  tabBar() {
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 2
      })
    }
  },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})